<script>
  import $ from '../dfish.js'
  import FormBase from './FormBase.vue'

  export default {
    name: 'w-text',
    mixins: [FormBase],
    props: ['minLength', 'maxLength', 'pattern'],
    data() {
      return {
        hasBorder: true
      }
    },
    computed: {
      validHooks() {
        return {
          ...this.pubValidHooks,
          minLength: (v, r, q) => {
            if (v && r != null && r !== '' && r > 0 && $.strLen(v) < r)
              return this.formErr(q, [r])
          },
          maxLength: (v, r, q) => {
            let d
            if (v && r != null && r !== '' && r > 0 && v && (d = $.strLen(v)) > r)
              return this.formErr(q, [d - r])
          },
        }
      },
    }
  }
</script>
